package com.noble.glamour.third.screenshot;

import android.app.Activity;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import com.tarek360.instacapture.exception.IllegalScreenSizeException;

import rx.Observable;
import rx.functions.Func0;

/**
 * 获取截屏
 */
public final class ViewsBitmapObservable {

  private ViewsBitmapObservable() {

  }

  @NonNull
  public static Observable<Bitmap> get(@NonNull final Activity activity, @NonNull final View appointView,
                                       @Nullable final View[] removedViews) {

    return Observable.defer(new Func0<Observable<Bitmap>>() {
      @Override
      public Observable<Bitmap> call() {

        Bitmap screenBitmap = ScreenshotTaker.getScreenshotBitmap(activity, appointView, removedViews);
        if (screenBitmap != null) {
          return Observable.just(screenBitmap);
        } else {
          return Observable.error(new IllegalScreenSizeException());
        }
      }
    });
  }
}
